package com.ruoyi.cms.controller;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/live")
@CrossOrigin
public class LiveController extends BaseController {

    @PostMapping("/login")
    public AjaxResult login(String username, String password){
        if(!password.equals("123")){
            return AjaxResult.error();
        }

        //  webrtc://202316.push.tlivecloud.com/live/huawei?txSecret=48a17a64ae78c3630b3e14990b76ff81&txTime=6699E310

        String txSecret = "";
        String txTime = "";

        long time = System.currentTimeMillis() / 1000 + 3600;
        txTime = Long.toHexString(time).toUpperCase();

        String param = "6ad701e41c6025b1c3947a69bcd9f6e1"+username+txTime;
        txSecret = DigestUtils.md5Hex(param);

        Map map = new HashMap<>();
        map.put("txTime", txTime);
        map.put("txSecret", txSecret);

        return AjaxResult.success(map);
    }
}
